<template>
  <div class="sing">
    <form>
    <div class="box">
      <h2>注册</h2>
      <div class="inputs">
        <div>
          <input
            name="user"
            type="text"
            placeholder="User"
            :value="name"
            @keyup="nameValue"
          />
        </div>
        <div>
          <input
            name="email"
            type="email"
            placeholder="Email"
            :value="email"
            @keyup="emailValue"
          />
        </div>
        <div>
          <input
            name="password"
            type="password"
            placeholder="PassWord"
            autocomplete="off"
            :value="password"
            @keyup="passwordValue"
          />
        </div>
        <div>
          <input
            name="code"
            type="text"
            placeholder="code"
            id="code"
            :value="code"
            @keyup="codeValue"
          />
        </div>
      </div>
      <div class="button">
        <span @click="pu">发送验证码</span>
        <button type="button" @click="si">注册</button>
      </div>
    </div>
    </form>
  </div>
</template>

<script>
import { inject, ref } from "vue";
import { Toast } from "vant";
import { useRouter } from 'vue-router';
import {sing ,pushCode} from "@/api/login"
export default {
  name: "Sing",
  setup() {
    const axios = inject("$http");
    const log = Toast;
    const router = useRouter()
    // input 框双向绑定
    let name = ref("");
    function nameValue(e) {
      name.value = e.target.value;
    }
    //
    let email = ref("");
    function emailValue(e) {
      email.value = e.target.value;
    }
    //
    let password = ref("");
    function passwordValue(e) {
      password.value = e.target.value;
    }
    let code = ref("");
    function codeValue(e) {
      code.value = e.target.value;
    }
    
    // 发送验证码 
    let inputs = []
    function pu(){
      inputs = [name.value,email.value,password.value]
      pushCode(log,inputs,axios,{email:email.value})
    }
    // 注册
    function si(){
      let inputs1 = [...inputs,code.value]
      sing(router,log,inputs1,axios,{name:name.value,email:email.value,password:password.value,code:code.value})
    }
    return {
      name,
      nameValue,
      email,
      emailValue,
      password,
      passwordValue,
      code,
      codeValue,
      pu,si,
    };
  },
};
</script>

<style scoped lang="scss">
.sing {
  width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: url("1.jpg") no-repeat 0 0/100%;
  .box {
    width: 50vh;
    height: 50vh;
    border-radius: 15px;
    background: rgba($color: white, $alpha: 0.7);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    h2 {
      text-align: center;
      font-size: 24px;
    }
    .inputs {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      div {
        width: 70%;
        padding: 1%;
        input {
          border: 1px solid #aaa;
          border-radius: 15px;
          outline: none;
          width: 100%;
          padding: 4%;
        }
        .val {
          border: 1px solid red;
        }
      }
    }
    .button {
      width: 100%;
      height: 70px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      span {
        font-size: 15px;
      }
      button {
        width: 80px;
        height: 30px;
        border-radius: 5px;
        border: none;
        background: rgba($color: #ff0000, $alpha: 0.7);
      }
    }
  }
}
</style>